/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.edu.thu.laud.utils.serde;

import java.nio.ByteBuffer;

/**
 * Interface that allows conversions of objects to bytes
 * @author zhuoan
 *
 */
public interface IConverter {

	/**
	 * Read the bytes from the byte buffer and return the object.  Assume the read mark is always set to the correct index as well as limit.
	 * Implementation should always assume that bytes between position and limit need to be read.  This allows the caller (such as association converters)
	 * to set the position and limit.
	 * 
	 * @param buffer
	 * @return
	 */
	public Object getObject(ByteBuffer buffer, ConverterContext context);
	
	
	/**
	 * Write the value to the given buffer.  Assume the write mark is always set to the correct index.
	 * The buffer that should be used for the next write operation is returned.  The implementation should be null safe
	 * and should also check the buffer size.  If null is passed the buffer should be allocated.  If the buffer is
	 * too small, a new instance should be allocated and returned with all bytes from the previous buffer.
	 * @param instance
	 * @return
	 */
	public ByteBuffer writeBytes(Object value, ByteBuffer buffer, ConverterContext context);
	
	/**
	 * Returns the comparator type (UTF-8, TimeUUIDType etc) that should be used when comparing the values in this column
	 * This is used for validation on secondary indexing.
	 * @return
	 */
	public String getComparatorType();
	
	
	
}
